package com.ss.android.article.browser.view.user.a;

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.download.internal.DownloadTask;

import java.util.ArrayList;
import java.util.List;

public final class d extends Adapter {
    public final class a extends ViewHolder {
        final TextView a;
        final TextView b;
        final ProgressBar c;
        final Context d;
        final TextView e;
        final View f;

        public a(View arg2) {
            super(arg2);
            this.a = arg2.findViewById(com.ss.android.article.browser.R.id.x9);
            this.b = arg2.findViewById(com.ss.android.article.browser.R.id.x8);
            this.c = arg2.findViewById(com.ss.android.article.browser.R.id.sf);
            this.e = arg2.findViewById(com.ss.android.article.browser.R.id.xa);
            this.d = arg2.getContext();
            this.f = arg2.findViewById(com.ss.android.article.browser.R.id.xb);
        }
    }

    public List a;

    public d() {

        this.a = new ArrayList();
    }

    public final int a(DownloadTask arg2) {
        return this.a.indexOf(arg2);
    }

    public final int getItemCount() {
        return this.a.size();
    }

    public final void onBindViewHolder(ViewHolder arg13, int arg14) {
        int v11 = 8;
        Object v0 = this.a.get(arg14);
        ((a)arg13).a.setText(((DownloadTask)v0).fileName);
        long v4 = ((DownloadTask)v0).totalSize;
        long v2 = ((DownloadTask)v0).finishedSize;
        double v6 = (((double)v4)) / 2147483647;
        if(v6 > 1) {
            v4 = 2147483647;
            v2 = ((long)(((int)((((double)v2)) / v6))));
        }

        String v1 = com.ss.android.article.browser.download.b.a.a(v2);
        String v6_1 = com.ss.android.article.browser.download.b.a.a(v4);
        ((a)arg13).c.setProgress(((int)((((float)v2)) / (((float)v4)) * 100f)));
        ((a)arg13).b.setText(v1 + "/" + v6_1);
        switch(e.a[((DownloadTask)v0).downloadState.ordinal()]) {
            case 1: {
                ((a)arg13).e.setText(((a)arg13).d.getString(com.ss.android.article.browser.R.string.download_fail));
                UIUtils.setVisibility(((a)arg13).e, 0);
                UIUtils.setVisibility(((a)arg13).f, v11);
                break;
            }
            case 2: {
                ((a)arg13).e.setText(((a)arg13).d.getString(com.ss.android.article.browser.R.string.pf));
                UIUtils.setVisibility(((a)arg13).e, 0);
                UIUtils.setVisibility(((a)arg13).f, v11);
                break;
            }
            case 3: {
                ((a)arg13).e.setText(((a)arg13).d.getString(com.ss.android.article.browser.R.string.paused));
                UIUtils.setVisibility(((a)arg13).e, 0);
                UIUtils.setVisibility(((a)arg13).f, v11);
                break;
            }
            case 4: {
                UIUtils.setVisibility(((a)arg13).f, 0);
                UIUtils.setVisibility(((a)arg13).e, v11);
                break;
            }
            case 5: {
                ((a)arg13).b.setText(((a)arg13).d.getString(com.ss.android.article.browser.R.string.j8));
                UIUtils.setVisibility(((a)arg13).f, 0);
                UIUtils.setVisibility(((a)arg13).e, v11);
                break;
            }
        }
    }

    public final ViewHolder onCreateViewHolder(ViewGroup arg5, int arg6) {
        return new a(LayoutInflater.from(arg5.getContext()).inflate(com.ss.android.article.browser.R.layout.ek, arg5, false));
    }
}

